import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/table';
import { weChatList } from '@apps/ant-bus/src/views/business/platformManage/wechat/data/api';

export const columns: BasicColumn[] = [
  {
    title: '企业Id',
    dataIndex: 'companyId',
    width: 280,
  },
  {
    title: '企业名称',
    dataIndex: 'companyName',
    width: 160,
  },
  {
    title: '企业昵称',
    dataIndex: 'companyNickName',
    width: 160,
  },
  {
    title: '接口密钥',
    dataIndex: 'companySecret',
    width: 280,
  },
  {
    title: '联系人',
    dataIndex: 'linkMan',
    width: 100,
  },
  {
    title: '合作状态',
    dataIndex: 'companyState',
    width: 80,
    customRender: ({ record }: Recordable) => {
      const companyStateArray = [
        { label: '未合作', value: 0 },
        { label: '合作', value: 1 },
      ];
      const companyState: any = companyStateArray.find(item => item.value == record.companyState);
      if (companyState) {
        return companyState.label;
      }
      return '';
    },
  },
  {
    title: '地址',
    dataIndex: 'address',
    width: 100,
  },
  {
    title: '公司电话',
    dataIndex: 'companyTel',
    width: 100,
  },
  {
    title: '公司余额',
    dataIndex: 'amount',
    width: 100,
  },
  {
    title: '过期日期',
    dataIndex: 'expireDate',
    width: 100,
  },
  {
    title: '公众号',
    dataIndex: 'weChatName',
    width: 150,
  },
  {
    title: '创建日期',
    dataIndex: 'createTime',
    width: 150,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'companyName',
    label: '企业名称',
    component: 'Input',
    colProps: { span: 5 },
  },
  {
    field: 'companyNickName',
    label: '企业昵称',
    component: 'Input',
    colProps: { span: 5 },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '企业Id',
    field: 'companyId',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    label: '公司名称',
    field: 'companyName',
    component: 'Input',
    required: true,
  },
  {
    label: '公司昵称',
    field: 'companyNickName',
    component: 'Input',
    required: true,
  },
  {
    label: '公司电话',
    field: 'companyTel',
    component: 'Input',
    required: true,
  },
  {
    label: '公司LOGO',
    field: 'companyLogo',
    component: 'ImageUpload',
    required: false,
  },
  {
    label: '密钥',
    field: 'companySecret',
    component: 'Input',
    required: true,
    ifShow({ model }) {
      if (model.companyId) {
        return true;
      } else {
        return false;
      }
    },
    dynamicDisabled: ({ model }) => {
      if (model.companyId) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '联系人',
    field: 'linkMan',
    component: 'Input',
    required: true,
  },
  {
    label: '合作状态',
    field: 'companyState',
    component: 'Select',
    required: true,
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '未合作', value: 0 },
        { label: '合作', value: 1 },
      ],
    },
  },
  {
    label: '过期日期',
    field: 'expireDate',
    component: 'DatePicker',
    required: true,
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'weChatId',
    label: '所属公众号',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: weChatList,
      params: {},
      labelField: 'weChatName',
      valueField: 'weChatId',
      immediate: true,
    },
  },
  {
    label: '地址',
    field: 'address',
    component: 'InputTextArea',
    required: false,
  },
];

export const rechargeFormSchema: FormSchema[] = [
  {
    label: '企业Id',
    field: 'companyId',
    component: 'Input',
    required: true,
    show: false,
  },
  {
    label: '版本号',
    field: 'version',
    component: 'InputNumber',
    required: true,
    dynamicDisabled: true,
  },
  {
    label: '充值金额',
    field: 'rechargeAmount',
    component: 'InputNumber',
    required: true,
  },
  {
    label: '是否付款',
    field: 'isRealPay',
    component: 'Select',
    required: true,
    defaultValue: 2,
    componentProps: {
      options: [
        { label: '已支付', value: 1 },
        { label: '未支付', value: 2 },
      ],
    },
  },
];
